package com.nativetalk.controller.app.teacher.update;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.teacher.TdNtTeacherResult;
import com.nativetalk.bean.teacher.TdNtTeacherSound;
import com.nativetalk.common.Constants;
import com.nativetalk.common.util.JsonUtil;
import com.nativetalk.common.util.MemcachedUtils;
import com.nativetalk.controller.app.three.study.ThreeStudyController;
import com.nativetalk.service.teacher.update.TeacherUpdateService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;

/**
 * Created by wuyuanhui on 16/3/3.
 */
@Controller
public class SoundController {
    private static Logger logger = Logger.getLogger(SoundController.class);
    @Resource
    private TeacherUpdateService teacherUpdateService;
    /**
     * @Purpose  修改教师声音简历
     * @version  1.0
     * @time     2015-03-03
     * @author   wuyuanhui
     * @return   RetInfo
     */
    @RequestMapping(value="/app/2/teatoken/teacher/update/updateSound" ,method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public RetInfo updateSound( @ModelAttribute TdNtTeacherSound tdNtTeacherSound,
                                  @RequestHeader(value = "token", required = true) String token) throws  IOException{
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(tdNtTeacherSound));

            RetInfo retInfo;
            TdNtTeacherResult tdNtTeacherResult = (TdNtTeacherResult) MemcachedUtils.get(token);
            tdNtTeacherSound.setTea_id(tdNtTeacherResult.getTea_id());
            retInfo = teacherUpdateService.updateTeacherSound(tdNtTeacherSound,tdNtTeacherResult);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }
}